package com.jy.project.util;

public class ServiceResultUtils<T> {
    /**
     *
     */
    private static final long serialVersionUID = 7594073105833045644L;

    private boolean success = false;

    private String code;

    private String message;

    private T data;

    private ServiceResultUtils() {
    }
    public static <T> ServiceResultUtils<T> success() {
        ServiceResultUtils<T> item = new ServiceResultUtils<T>();
        item.success = true;
        item.data = null;
        item.code = "0";
        item.message = "操作成功";
        return item;
    }

    public static <T> ServiceResultUtils<T> success(T data) {
        ServiceResultUtils<T> item = new ServiceResultUtils<T>();
        item.success = true;
        item.data = data;
        item.code = "0";
        item.message = "操作成功";
        return item;
    }
    public static <T> ServiceResultUtils<T> failure(String errorCode, String errorMessage) {
        ServiceResultUtils<T> item = new ServiceResultUtils<T>();
        item.success = false;
        item.code = errorCode;
        item.message = errorMessage;
        return item;
    }


    public static <T> ServiceResultUtils<T> failure(String messgae) {
        ServiceResultUtils<T> item = new ServiceResultUtils<T>();
        item.success = false;
        item.code = "-1";
        item.message = messgae;
        return item;
    }

    public static <T> ServiceResultUtils<T> failure() {
        ServiceResultUtils<T> item = new ServiceResultUtils<T>();
        item.success = false;
        item.code = "-1";
        item.message = "操作失败";
        return item;
    }
    public boolean hasData() {
        return data != null;
    }

    public boolean isSuccess() {
        return success;
    }

    public T getData() {
        return data;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
